<?php

require __DIR__ . '/../../vendor/autoload.php';
include "ccc.php";

use LDL\Twspider\Twspider;
class MyWork extends Threaded {
    public function __construct() {
        global $a;
     //   var_dump($a);exit ;
        echo "cccc xxxx\n ";
        $this->a= $a ;

        $this->complete = false;
    }
    function __clone(){
        echo "cl xxx\n";
    }
    function __destruct(){
    echo "die xxxx\n ";

}
   public function run() {

       $this->a->a();

       printf(
            "Hello from %s in Thread #%lu\n",
            __CLASS__, $this->worker->getThreadId());
       usleep(40000);
       printf(
           "xxx from %s in Thread #%lu\n",
           __CLASS__, $this->worker->getThreadId());

       $this->complete = true;
    }

    public function isComplete() {
        return $this->complete;
    }

    protected $complete;
}

class MyWorker extends Worker {

    public function __construct( $something) {
      //  $this->something = $something;
    }

    public function run() {
  //      echo "xxxxxxx\n";
    }
    function __destruct(){
       // echo "woer die ...... xxxx\n ";

    }
}

$pool = new Pool(8, \MyWorker::class, ["xxxxx"]);
//$pool->submit(new MyWork());

//$pool->submit();

$pool->submit(new MyWork());
/*
$pool->submit(new MyWork());

$pool->submit(new MyWork());

$pool->submit(new MyWork());

$pool->submit(new MyWork());

$pool->submit(new MyWork());
$pool->submit(new MyWork());
$pool->submit(new MyWork());

$pool->submit(new MyWork());

$pool->submit(new MyWork());

$pool->submit(new MyWork());

$pool->submit(new MyWork());
*/

//usleep(1000);
//var_dump($pool);

$pool->collect(function($work){
    printf(
        "collect %d\n",
        $work->isComplete());
    return   $work->isComplete();
});


//$pool->shutdown();
//sleep(30);
//$pool->submit(new MyWork());
echo "xxx";

$v = new Twspider("http://www.baidu.com");$v->crawl();
//var_dump($pool);
?>
